<#macro upload_plupload name="file" maxSize='10mb' url=''>
<div id="uploader">
	<p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
</div>
<!--flick-->
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/themes/flick/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="${base}/resources/scripts/plupload/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />

<script type="text/javascript" src="${base}/resources/scripts/jquery/jquery-ui.min.js"></script>

<!-- production -->
<script type="text/javascript" src="${base}/resources/scripts/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="${base}/resources/scripts/plupload/jquery.ui.plupload/jquery.ui.plupload.js"></script>
<script type="text/javascript" src="${base}/resources/scripts/plupload/zh_CN.js"></script>

<script type="text/javascript">
// Initialize the widget when the DOM is ready
$(function() {
	$("#uploader").plupload({
		// General settings
		runtimes : 'html5,flash,silverlight,html4',
		url : '${url}',
		file_data_name:"${name}",
		// User can upload no more then 20 files in one go (sets multiple_queues to false)
		max_file_count: 20,
		//chunk_size: '1mb',

		// Resize images on clientside if we can
		filters : {
			// Maximum file size
			max_file_size : '${maxSize}',
			// Specify what files to browse for
			mime_types: [
				{title : "请选择图片", extensions : "jpg,gif,png,bmp,JPEG"}
			]
		},

		// Rename files by clicking on their titles
		rename: true,
		
		// Sort files
		sortable: true,

		// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
		dragdrop: true,

		// Views to activate
		views: {
			list: true,
			thumbs: true, // Show thumbs
			active: 'thumbs'
		},
		FileUploaded : function(up, file, responseText){
			console.log(up, file, responseText);
		}
	});
	pluploader.bind("FileUploaded", function(up, file, responseText){
		console.log(up, file, responseText);
		//判断是否有错
		var re = $.parseJSON(responseText.response);
		if(re.success === true){
			$("#uploader").plupload('removeFile', file.id);
			$('#uploader').plupload('refresh');
		}else{
			var $file = $('#' + file.id), 
					actionClass='ui-state-error plupload_failed',
					iconClass='plupload_action_icon ui-icon ui-icon-alert';
			actionClass += ' ui-state-default plupload_file';
			$file
				.attr('class', actionClass)
				.find('.plupload_action_icon')
					.attr('class', iconClass);
		}
	});
	$('#uploader').on("complete", function(){
		var fs = $('#uploader').plupload('getFiles');
		for(var i=0;i<fs.length; i++)
			fs[i].status = plupload.QUEUED;
		if(fs.length>0)
			$('#uploader').plupload('toStart');//设置可以上传图片
	});
});
</script>
</#macro>